//
//  ZZUserInfoCell.m
//  QQplayground
//
//  Created by zhangxy on 2018/6/7.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZUserInfoCell.h"
#import "ZZHomeTopMenu.h"
#import "UIImage+ImageWithColor.h"

#import "MyUserController.h"
#import "ZZLeaveMessageController.h"
#import "MyGuestController.h"
#import "ZZVipController.h"
#import "UserInfoController.h"
@implementation ZZUserInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _imgAvatar.layer.cornerRadius = _imgAvatar.frame.size.height/2;
    _imgAvatar.layer.masksToBounds = YES;
    _imgAvatar.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeAvatar:)];
    [_imgAvatar addGestureRecognizer:tap];
    
    [self setLayerButton:_btnZan];
    [_btnZan.titleLabel setFont:FontSeventeen];
    [_btnZan setImage:[UIImage imageNamed:@"个人页点赞"] forState:UIControlStateNormal];
    [_btnZan setImage:[UIImage imageNamed:@"个人页点赞2"] forState:UIControlStateSelected];
    [_btnZan addTarget:self action:@selector(btnZanClick:) forControlEvents:UIControlEventTouchUpInside];
//    [_imgSex setImage:[UIImage imageNamed:@"sex_boy"]];
    
    [_labName setFont:[UIFont boldSystemFontOfSize:21]];
    [_labName setTextColor:UIColorFromRGB(TextWhiteColor)];
    
    [_btnLevel.titleLabel setFont:ListElevenFont];
    _btnLevel.layer.cornerRadius = 4.0f;
    //[_btnLevel setTextAlignment:NSTextAlignmentCenter];
    _btnLevel.layer.masksToBounds = YES;
    [_btnLevel setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    _btnLevel.userInteractionEnabled = NO;
    
    //_labLevel.layer.borderColor = UIColorFromRGB(BorderLineColor).CGColor;
    //[_labLevel setTextColor:UIColorFromRGB(TextWhiteColor)];
   // _labLevel.layer.borderWidth = 1.0f;
    
    //[_btnOpenVip setImage:[UIImage imageNamed:@"开通会员"] forState:0];
    [_btnOpenVip setBackgroundColor:UIColor.clearColor];
    [_btnOpenVip addTarget:self action:@selector(btnNumClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_labDesc setFont:ListElevenFont];
    [_labLabels setFont:ListElevenFont];
    [_labDesc setTextColor:UIColorFromRGB(TextWhiteColor)];
    [_labLabels setTextColor:UIColorFromRGB(TextWhiteColor)];
    
    [self setLayerButton:_btnDS];
    [self setLayerButton:_btnAge];
    [self setLayerButton:_btnCity];
    [self setLayerButton:_btnQQ];
    
    [_btnZanYellow setImage:[UIImage imageNamed:@"金币"] forState:0];
    [_btnZanYellow setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnZanYellow.titleLabel setFont:FontThirteen];
    [_btnZanYellow setBackgroundColor:UIColor.clearColor];
    
    
    [_btnZanCool setImage:[UIImage imageNamed:@"钻石"] forState:0];
    [_btnZanCool setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnZanCool.titleLabel setFont:FontThirteen];
    [_btnZanCool setBackgroundColor:UIColor.clearColor];
    
    
    [_btnTap1 setBackgroundColor:UIColor.clearColor];    
    [_btnTap1 setBackgroundImage:[UIImage imageNamed:@"素材"]  forState:UIControlStateSelected];
    [_btnTap1 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
    //[_btnTap1 setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(BgTitleColor)] forState:UIControlStateNormal];
    [_btnTap1 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateNormal];
    [_btnTap1.titleLabel setFont:ListElevenFont];
    [_btnTap1 setTitle:@"素材" forState:0];
    
    [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换 copy"] forState:UIControlStateSelected];
    [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换"] forState:UIControlStateNormal];
    [_btnTap1 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnTap1 setTintColor:UIColorFromRGB(TextWhiteColor)];
    [_btnTap2 setTintColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0]];
    [_btnTap2 setBackgroundColor:UIColor.clearColor];
    [_btnTap2 setBackgroundImage:[UIImage imageNamed:@"帖子"] forState:UIControlStateNormal];
    [_btnTap2 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateNormal];
    //[_btnTap2 setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(TextWhiteColor)] forState:UIControlStateSelected];
    [_btnTap2 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
    [_btnTap2.titleLabel setFont:ListElevenFont];
    [_btnTap2 setTitle:@"帖子" forState:0];
    
    [_btnTap2 setImage:[UIImage imageNamed:@"帖子 切换 copy"] forState:UIControlStateSelected];
    [_btnTap2 setImage:[UIImage imageNamed:@"帖子 切换"] forState:UIControlStateNormal];
    [_btnTap2 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_btnTap3 setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(BgTitleColor)] forState:UIControlStateNormal];
    [_btnTap3 setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(TextWhiteColor)] forState:UIControlStateSelected];
    [_btnTap3 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnTap3 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
    [_btnTap3.titleLabel setFont:ListElevenFont];
    [_btnTap3 setTitle:@"秘密" forState:0];
    [_btnTap3 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_viewNums setBackgroundColor:UIColor.clearColor];
    [_btnNum1 addTarget:self action:@selector(btnNumClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnNum2 addTarget:self action:@selector(btnNumClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnNum3 addTarget:self action:@selector(btnNumClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnNum4 addTarget:self action:@selector(btnNumClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //    [self.avatarImageView addGestureRecognizer:tap];
    [_imgAvatar addGestureRecognizer:tap];
//    CGRect f = _btnTap3.frame;
//    f.origin.x = f.origin.x - f.size.width;
//    [_btnTap2 setFrame:f];
//    f.origin.x = f.origin.x - f.size.width;
//    [_btnTap1 setFrame:f];
    
    [ZZViewUtils cutViewRound:_viewMenus radius:10 byRoundingCorners:UIRectCornerTopLeft];
    [_viewMenus setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
}

-(void)btnZanClick:(UIButton *) btn{
    if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
        [self.delegate onHeaderCellItemClick:ZZHeaderTypeZan obj:nil];
    }
    if ([_tempUser.user_is_like intValue] == 1){
        btn.selected = NO;
    } else {
        btn.selected = YES;
    }
}

-(void)tapClick:(UIButton *) btn{
    if([btn isEqual:_btnTap3]){
        
        _btnTap1.selected = NO;
        _btnTap2.selected = NO;
        _btnTap3.selected = YES;
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeMimi obj:nil];
        }
    }
    if([btn isEqual:_btnTap2]){
        _btnTap1.selected = NO;
        _btnTap2.selected = YES;
        _btnTap3.selected = NO;
    
        [_btnTap2 setTintColor:UIColorFromRGB(TextWhiteColor)];
        [_btnTap1 setTintColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0]];
      
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeTiezi obj:nil];
        }
    }
    if([btn isEqual:_btnTap1]){
        _btnTap1.selected = YES;
        _btnTap2.selected = NO;
        _btnTap3.selected = NO;
        [_btnTap1 setTintColor:UIColorFromRGB(TextWhiteColor)];
        [_btnTap2 setTintColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0]];
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeSucai obj:nil];
        }
    }
}

-(void)changeAvatar:(UITapGestureRecognizer *) tap{
    if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
        [self.delegate onHeaderCellItemClick:ZZHeaderTypeChangeAvatar obj:nil];
    }
}

-(void)btnNumClick:(UIButton *)btn{
    
    if([btn isEqual:_btnNum3]){
        ZZLeaveMessageController *vc = [[ZZLeaveMessageController alloc] init];
        vc.user_id = _tempUser.user_id;
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeOpenVC obj:vc];
        }
    }else if([btn isEqual:_btnOpenVip]){
        ZZVipController *vc = [[ZZVipController alloc] init];
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeOpenVC obj:vc];
        }
    }else{
        
        if([btn isEqual:_btnNum4]){
            MyGuestController *vc = [[MyGuestController alloc] init];
            vc.user_id = _tempUser.user_id;
            if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
                [self.delegate onHeaderCellItemClick:ZZHeaderTypeOpenVC obj:vc];
            }
        }else{
            MyUserController *vc = [[MyUserController alloc] init];
            vc.user_id = _tempUser.user_id;
            if([btn isEqual:_btnNum1]){
                vc.userType = MyUserAttent;
            }
            if([btn isEqual:_btnNum2]){
                vc.userType = MyUserFans;
            }
            if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
                [self.delegate onHeaderCellItemClick:ZZHeaderTypeOpenVC obj:vc];
            }
        }
        
        
    }
   
}


-(void)dataToView:(User *) user with:(UserPageDataType)type{
    _tempUser = user;
    if(type == UserPageDataSucai){
        _btnTap1.selected = YES;
        _btnTap2.selected = NO;
        _btnTap3.selected = NO;
    }else if(type == UserPageDataTopic){
        _btnTap1.selected = NO;
        _btnTap2.selected = YES;
        _btnTap3.selected = NO;
    }

//    if([_tempUser.user_id isEqual:[UserUtil getUser].user_id]){
//        _btnTap3.hidden = NO;
//        CGRect f1 = _btnTap1.frame;
//        CGRect f2 = _btnTap2.frame;
//        CGRect f3 = _btnTap2.frame;
//        f2.origin.x = ScreenWidth - f3.size.width - f2.size.width;
//        f1.origin.x = ScreenWidth - f3.size.width - f2.size.width- f1.size.width + 11;
//        _btnTap1.frame = f1;
//        _btnTap2.frame = f2;
//    }else{
        _btnTap3.hidden = YES;
        CGRect f1 = _btnTap1.frame;
        CGRect f2 = _btnTap2.frame;

        f2.origin.x = ScreenWidth - f2.size.width;
        f1.origin.x = ScreenWidth - f2.size.width- f1.size.width + 11;
        _btnTap1.frame = f1;
        _btnTap2.frame = f2;
//    }
    
    [_imgAvatar sd_setImageWithURL:[NSURL URLWithString:user.user_avatar] placeholderImage:[UIImage imageNamed:@"default_image"]];
    [_labName setText:user.user_name];
    [_labName sizeToFit];
    [self autoWidthOfLabel:_labName with:21];
    CGRect levelF = _btnLevel.frame;
    levelF.origin.x = CGRectGetMaxX(_labName.frame) + 5;
    _btnLevel.frame = levelF;
    [self setBtnLevelColor:user];
    //[ZZViewUtils setBtnLevelColor:user btn:_btnLevel];
    
    [_btnZan setTitle:user.user_like forState:0];
//    if(user.user_gender == 1){
//        [_imgSex setImage:[UIImage imageNamed:@"sex_boy"]];
//    }else{
//        [_imgSex setImage:[UIImage imageNamed:@"sex_girl"]];
//    }
    [_labDesc setText:(user.user_sign.length>0 ? user.user_sign : Unpublish_sign)];
    _labDesc.numberOfLines = 0;
//    [_labLabels setText:user.group_name];
    
    [_labLabels setText:[NSString stringWithFormat:@"乐园号:%@",user.user_id]];
    //[_btnDS setTitle:user.user_emotion forState:0];
    
    
//    if(convertToString(user.birth_year).length > 0 && convertToString(user.birth_month).length > 0 && convertToString(user.birth_day).length > 0){
//        if([user.birth_day intValue] < 10){
//            user.birth_day = [NSString stringWithFormat:@"0%@",user.birth_day];
//        }
//        if([user.birth_month intValue] < 10){
//            user.birth_month = [NSString stringWithFormat:@"0%@",user.birth_month];
//        }
//        NSString *birday = [NSString stringWithFormat:@"%@-%@-%@",user.birth_year,user.birth_month,user.birth_day];
//        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//        // this is imporant - we set our input date format to match our input string
//        // if format doesn't match you'll get nil from your string, so be careful
//        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
//        NSDate *birthday = [dateFormatter dateFromString:birday];
//        [_btnAge setTitle:[NSString stringWithFormat:@"%@岁",dateToAge(birthday)] forState:0];
//    }else{
//        [_btnAge setTitle:@"未填写" forState:0];
//    }
//    [_btnCity setTitle:user.user_constellation forState:0];
//    if(convertToString(user.user_qq).length > 1){
//
//        [_btnQQ setTitle:[NSString stringWithFormat:@"QQ%@",convertToString(user.user_qq)] forState:0];
//    }else{
//        [_btnQQ setTitle:[NSString stringWithFormat:@"未填写"] forState:0];
//    }
    
    [self setBtnNumMessage:[NSString stringWithFormat:@"%@ 关注",convertToString(user.count_follow)] btn:_btnNum1];
    [_btnNum1 sizeToFit];
    
    int distance = 10;
    CGRect tempf = _btnNum2.frame;
    tempf.origin.x = CGRectGetMaxX(_btnNum1.frame) + distance;
    _btnNum2.frame = tempf;
    [self setBtnNumMessage:[NSString stringWithFormat:@"%@ 粉丝",convertToString(user.count_fans)] btn:_btnNum2];
    [_btnNum2 sizeToFit];
    
    tempf = _btnNum3.frame;
    tempf.origin.x = CGRectGetMaxX(_btnNum2.frame) + distance;
    _btnNum3.frame = tempf;
    [self setBtnNumMessage:[NSString stringWithFormat:@"%@ 留言",convertToString(user.count_wall)] btn:_btnNum3];
    [_btnNum3 sizeToFit];
    
    tempf = _btnNum4.frame;
    tempf.origin.x = CGRectGetMaxX(_btnNum3.frame) + distance;
    _btnNum4.frame = tempf;
    [self setBtnNumMessage:[NSString stringWithFormat:@"%@ 访客",convertToString(user.count_visit)] btn:_btnNum4];
    [_btnNum4 sizeToFit];
    
    [_btnZanYellow setTitle:user.user_gold forState:0];
    [_btnZanCool setTitle:user.user_diamond forState:0];
    
    
    [_btnOpenVip setTitle:@"" forState:0];
    if ([self isMySelf]){
        _btnOpenVip.userInteractionEnabled = YES;
        if ([user.is_vip isEqualToString:@"0"]){
            [_btnOpenVip setImage:[UIImage imageNamed:@"开通会员"] forState:0];
        } else{
            [_btnOpenVip setImage:[UIImage imageNamed:@"vip"] forState:0];
        }
    } else {
        if ([user.is_vip isEqualToString:@"1"]){
            [_btnOpenVip setImage:[UIImage imageNamed:@"vip"] forState:0];
        }
        _btnOpenVip.userInteractionEnabled = NO;
    }

    _btnTap1.hidden = YES;
    _btnTap2.hidden = YES;
    _btnTap3.hidden = YES;
    _viewMenus.hidden = YES;
    
//    [_viewMenus setFrame:CGRectMake(0, CGRectGetMaxY(_btnTap1.frame)-1, ScreenWidth, 12)];
//    [ZZViewUtils cutViewRound:_viewMenus radius:10 byRoundingCorners:UIRectCornerTopLeft];
    [self setFrame:CGRectMake(0, NavBarHeight, ScreenWidth, CGRectGetMaxY(_btnNum1.frame))];
}
-(BOOL) isMySelf{
    return [_tempUser.user_id isEqual:[UserUtil getUser].user_id];
}
-(void)setBtnNumMessage:(NSString *) str btn:(UIButton *) btn{
    [btn setTitle:str forState:0];
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btn.titleLabel setFont:FontThirteen];
    
}



-(void)setLayerButton:(UIButton *) btn{
    [btn setBackgroundColor:UIColorFromRGBAlpha(TextWhiteColor, 0.4)];
    btn.layer.cornerRadius = btn.frame.size.height / 2;
    btn.layer.masksToBounds = YES;
    [btn.titleLabel setFont:ListElevenFont];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateSelected];
}

/**
 计算Label高度
 
 @param label 要计算的label，设置了值
 @param width label的最大宽度
 */
- (CGSize )autoWidthOfLabel:(UILabel *)label with:(CGFloat )height{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(FLT_MAX, height);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.width = expectedLabelSize.width;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//用户等级数的显示问题
-(void)setBtnLevelColor:(User *)user {
    int level = [user.group_icon intValue];
    if (level >= 100){
        CGRect lf = _btnLevel.frame;
        lf.size.width = 75;
        _btnLevel.frame = lf;
        [_btnOpenVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y - 2, 52, 18)];
        if (level == 100){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"荣誉会员"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"荣誉会员"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 101){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"官方团队"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"官方团队"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 403){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"1"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"系统屏蔽"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"系统屏蔽"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#A4A4A4" alpha:1.0] forState:0];
        } else if (level == 102){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"小组长"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"小组长"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 200){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"原创达人"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"原创达人"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        } else if (level == 201){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"专题小编"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"专题小编"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        }
    }
    
    else {
        //等级显示处理
        CGRect lf = _btnLevel.frame;
        [self autoWidthOfLabel:_labName with:21];
        lf.origin.x = CGRectGetMaxX(_labName.frame) + 5;
        _btnLevel.frame = lf;
        [_btnOpenVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y - 2, 52, 18)];
        if (level >= 1 && level < 6){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"1"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 1"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv 0%@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#A4A4A4" alpha:1.0] forState:0];
        } else if (level >= 6 && level < 11) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"2"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 2"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#1BC156" alpha:1.0] forState:0];
        } else if (level >= 11 && level < 16) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"3"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 3"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#4A90E2" alpha:1.0] forState:0];
        } else if (level >= 16 && level < 21) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 4"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        } else if (level >= 21 && level < 26) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 5"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
        } else if (level >= 26 && level < 31) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 6"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
        } else if (level >= 31 && level < 36) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"7"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 7"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
        } else if (level >= 36 && level < 41) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"8"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 8"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#3785FF" alpha:1.0] forState:0];
        } else if (level >= 41 && level < 46) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 9"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#962BFF" alpha:1.0] forState:0];
        } else if (level >= 46 && level < 51) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 10"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level >= 51 && level < 56) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"11"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 11"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
        } else if (level >= 56 && level < 100) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"12"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 12"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",user.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFFFFF" alpha:1.0] forState:0];
        }
    }
    
}
@end
